import React, { Component } from 'react'
import { CountConsumer } from './CounterContext'

export default class CounterButton extends Component {
  render() {

    let type = this.props.type;
    let buttonText = type === 'increment' ? '+' : '-'
    return (
      <CountConsumer>
        {
          ({ increment, decrement }) => {
            return (
              <button onClick={() => {
                if (type === 'increment') {
                  increment();
                }else{
                  decrement();
                }
              }}>
                {buttonText}
              </button>
            )
          }
        }
      </CountConsumer>

    )
  }
}
